﻿<Window x:Class="ResourceBlender_Express.WinDuplicateDetails"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:loc="clr-namespace:ResourceBlender_Express"
    loc:WindowService.EscapeClosesWindow="True"
    Title="Duplicate Details" WindowStartupLocation="CenterOwner"
    MinHeight="400" Height="470" MinWidth="400" Width="800"
    Style="{StaticResource {x:Type Window}}" Icon="/ResourceBlender-Express;component/Resources/images/resourceblender.ico">
    <Window.CommandBindings>
        <CommandBinding Command="loc:ResourceBlenderCommands.MergeDuplicates" Executed="MergeDuplicates" CanExecute="CanExecuteMergeDuplicates" />
        <CommandBinding Command="loc:ResourceBlenderCommands.ExpandDuplicateDetails" Executed="ExpandDuplicateDetails" />
        <CommandBinding Command="loc:ResourceBlenderCommands.SelectAll" Executed="SelectAllResources" CanExecute="CanExecuteSelectAll" />
        <CommandBinding Command="loc:ResourceBlenderCommands.Edit" Executed="EditResource" CanExecute="CanEditOrDelete"  />
        <CommandBinding Command="loc:ResourceBlenderCommands.Delete" Executed="DeleteResource" CanExecute="CanEditOrDelete" />
    </Window.CommandBindings>
    <Window.Resources>
        <Image x:Key="Merge_16" Source="pack://application:,,,/Resources/images/merge_16.png" />
        <Image x:Key="Edit_16" Source="pack://application:,,,/Resources/images/resource_edit_16.png" />
        <Image x:Key="Delete_16" Source="pack://application:,,,/Resources/images/resource_delete_16.png" />
    </Window.Resources>
    <DockPanel LastChildFill="True">
        <StatusBar DockPanel.Dock="Bottom" Height="24">
            <StatusBarItem x:Name="lblStatus" Visibility="Hidden">Loading</StatusBarItem>
            <ProgressBar x:Name="prgStatus" IsIndeterminate="True" Visibility="Hidden" />
        </StatusBar>
        
        <ToolBar DockPanel.Dock="Top" Height="58">
            <loc:ImageButton x:Name="btnEdit" Command="loc:ResourceBlenderCommands.Edit" Text="Edit" Image="Resources/images/resource_edit_24.png" ToolTip="Edit Resource" Style="{StaticResource ToolBarButton}" />
            <loc:ImageButton x:Name="btnDelete" Command="loc:ResourceBlenderCommands.Delete" Text="Delete Selected" Image="Resources/images/resource_delete_24.png" ToolTip="Delete Resources" Style="{StaticResource ToolBarButton}" />
            <Separator />
            <loc:ImageButton Command="loc:ResourceBlenderCommands.MergeDuplicates" Text="Merge Selected" Image="Resources/images/unused_24.png" ToolTip="Merge Selected Resources" Style="{StaticResource ToolBarButton}" />
            <loc:ImageButton Command="loc:ResourceBlenderCommands.SelectAll" Text="Select All" Image="Resources/images/selectall_24.png" ToolTip="Select All Resources" Style="{StaticResource ToolBarButton}" />
        </ToolBar>
        
        <ListView x:Name="lstGrid" DockPanel.Dock="Top" Margin="6" ItemsSource="{Binding}" GridViewColumnHeader.Click="OnColumnHeaderClick" MouseDoubleClick="FireEditResource" SelectionMode="Extended" SelectedValuePath="tid">
            <ListView.Resources>
                <Style TargetType="{x:Type TextBlock}">
                    <Setter Property="ToolTip" Value="{Binding RelativeSource={RelativeSource Self}, Path=Text}" />
                    <Setter Property="TextTrimming" Value="CharacterEllipsis" />
                    <Style.Triggers>
                        <DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=Text}" Value="">
                            <Setter Property="ToolTip" Value="{x:Null}" />
                        </DataTrigger>
                    </Style.Triggers>
                </Style>
            </ListView.Resources>
            <ListView.View>
                <GridView x:Name="grdResources">
                    <GridViewColumn Header="ID">
                        <GridViewColumn.CellTemplate>
                            <DataTemplate DataType="tid">
                                <CheckBox IsChecked="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListViewItem}},Path=IsSelected}" Content="{Binding tid}" VerticalAlignment="Center" VerticalContentAlignment="Center" />
                            </DataTemplate>
                        </GridViewColumn.CellTemplate>
                    </GridViewColumn>
                    <GridViewColumn Header="Used By" Width="200">
                        <GridViewColumn.CellTemplate>
                            <DataTemplate DataType="numelements">
                                <TreeView>
                                    <TreeViewItem Header="{Binding Path=numelements}" HeaderStringFormat="{}{0} elements" Expanded="ExpandDuplicateDetails" Tag="{Binding tid}">
                                        <TreeViewItem Header="No elements use this resource" Tag="false" />
                                        <!-- false to signify elements this resource uses have not yet been checked -->
                                    </TreeViewItem>
                                </TreeView>
                            </DataTemplate>
                        </GridViewColumn.CellTemplate>
                    </GridViewColumn>
                </GridView>
            </ListView.View>
            <ListView.ContextMenu>
                <ContextMenu>
                    <MenuItem Header="_Merge Selected" Icon="{StaticResource Merge_16}" Command="loc:ResourceBlenderCommands.MergeDuplicates" />
                    <Separator />
                    <MenuItem Header="_Edit" Icon="{StaticResource Edit_16}" Command="loc:ResourceBlenderCommands.Edit" />
                    <MenuItem Header="_Delete" Icon="{StaticResource Delete_16}" Command="loc:ResourceBlenderCommands.Delete" />
                </ContextMenu>
            </ListView.ContextMenu>
        </ListView>
    </DockPanel>
</Window>
